<?php

/*
 * Copyright by Sygma Media Inovasi Ω2013
 * 
 * Lead Programmer : Sony K Wibisono,S.Si,M.T.I
 * E-mail : sony@sonywibisono.com
 * 
 * Designer : Mr. Agus
 * 
 */
class Contents {
    var $id;
    var $title;
    var $content;
    var $created_on;
    var $updated_onn;
    var $revision;
    var $viwed;


    function open(){
        global $db;
        $sql="select * from contents where id=$id";
        $row=$db->fetch_row($sql);
        if (!empty($row)){
            extract($row);
            $this->title=$title;
            $this->content=$content;
            $this->created_on=$created_on;
            $this->updated_onn=$updated_onn;
            $this->revision=$revision;
            $this->viwed=$viwed;

        }
    }

    function openAll(){
        $sql="select * from contents order by id asc";
        $result=$db->query($sql);
        return $db->fetch_array($result);
        
    }

    function insert(){
    global $db;
    $sql="insert into contents values (null,'{$this->title}',
        '{$this->content}',sysdate(),null,1,0)";
    $db->query($sql);
    return mysql_insert_id();
    }

    function update(){
        global $db;
        $sql="update contents set title='{$this->title}',
            content='{$this->content}',
            updated_onn=sysdate,revision=revision+1
            viwed='{$this->viwed}' where id=".$this->id;
        $db->query($sql);
    }

    function delete(){
        global $db;
        $sql="delete from contents where id=".$this->id;
        $db->query($sql);
    }

}
?>
